package com.work.demo.test;
import java.security.Key;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.spec.IvParameterSpec;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class Encrypt {
    private static Key key;
    private static final String KEY_STR = "U2FsdGVkX1/YBR9lPPHtCsnE/OnRVvOYrQGtxOuvV/M=";
    private static final String CHARSETNAME = "UTF-8";
    private static final String ALGORITHM = "AES";
    private static final String ALGORITHM_MODE = "AES/CBC/PKCS5Padding";
    private static final String iv = "ajckfnst1024fnsb";

    static {
        try {
            KeyGenerator keygen = KeyGenerator.getInstance("AES");
            SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
            secureRandom.setSeed("U2FsdGVkX1/YBR9lPPHtCsnE/OnRVvOYrQGtxOuvV/M=".getBytes());
            keygen.init(128, secureRandom);
            key = keygen.generateKey();
            keygen = null;
        } catch (Exception var2) {
            throw new RuntimeException();
        }
    }

    public Encrypt() {
    }

    public static String getEncryptString(String content) {
        BASE64Encoder base64encoder = new BASE64Encoder();

        try {
            IvParameterSpec ivspec = new IvParameterSpec("ajckfnst1024fnsb".getBytes());
            byte[] bytes = content.getBytes("UTF-8");
            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
            cipher.init(1, key, ivspec);
            byte[] doFinal = cipher.doFinal(bytes);
            return base64encoder.encode(doFinal);
        } catch (Exception var6) {
            throw new RuntimeException();
        }
    }

    public static String getDecryptString(String encryptStr) {
        BASE64Decoder base64decoder = new BASE64Decoder();

        try {
            IvParameterSpec ivspec = new IvParameterSpec("ajckfnst1024fnsb".getBytes());
            byte[] bytes = base64decoder.decodeBuffer(encryptStr);
            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
            cipher.init(2, key, ivspec);
            byte[] doFinal = cipher.doFinal(bytes);
            return new String(doFinal, "UTF-8");
        } catch (Exception var6) {
            throw new RuntimeException();
        }
    }

    public static void main(String[] args) {
//        String type = args[0];
//        String oripsss = args[1];
//        if (type.equals("1")) {
//            System.out.print();
//        } else if (type.equals("2")) {
//            System.out.print(getDecryptString(oripsss));
//        }
System.out.println(getEncryptString("CzjPVpjthpCRz(X1g"));
    }
}